package com.maggroup.conference_system.common.utils;

import java.util.ArrayList;
import java.util.List;

import org.apache.commons.lang3.StringUtils;

import com.hankcs.hanlp.dictionary.stopword.CoreStopWordDictionary;
import com.hankcs.hanlp.seg.common.Term;
import com.hankcs.hanlp.tokenizer.StandardTokenizer;

/**
 * hanlp分词工具类
 * @author peng
 *
 */
public class HanLPUtil {
   
    public static List<String> segment(String text) {
        if (StringUtils.isNotEmpty(text)) {
            List<Term> list = StandardTokenizer.segment(text);
            List<String> result = new ArrayList<>(list.size());
            for (Term term : list) {
            	if((term.nature.startsWith("m")) ||   //数词过滤
            			(term.nature.startsWith("q")) ||  //量词过滤
            					(term.nature.startsWith("t")) ||  //时间词过滤
            							(term.nature.startsWith("w")) || //过滤标点符号
            								(CoreStopWordDictionary.contains(term.word))) // 停用词过滤
            	{
            		 
            	}else {
            		result.add(term.word);
				}
            }
            return result;
        }
        return null;
    }
  
}
